package func

import java.io.{File, PrintWriter}

/**
 *
 * @author tzp
 * @since 2021/1/16
 */
object NewControl {
  def withPrintWriter(file: File)(op: PrintWriter => Unit) = {
    val writer = new PrintWriter(file)
    try {
      op(writer)
    } finally {
      writer.close()
    }
  }

  def main(args: Array[String]): Unit = {
    withPrintWriter(new File("/Users/tzp/Documents/private/cnm/Trial-7-Lan/ScalaTest/scala_idea/out/xx")) {
      writer => writer.println("aa")
    }
  }
}
